Skip to content

feat: Adding support for ResVPNProxy data#243

Merged
clintjedwards merged 1 commit intomainfrom
cje/resvpnproxy
Apr 2, 2026
Merged

feat: Adding support for ResVPNProxy data#243
clintjedwards merged 1 commit intomainfrom
cje/resvpnproxy

Conversation

@clintjedwards
Copy link
Copy Markdown
Contributor

Adding a lookup function for ResVPNProxy. This enables VPN/Proxy intelligence data for specific IP addresses.

Most of this code is copied from other implementations for features, I figured we could start with an extra call off of fsthttp and then if we needed later we could make a standalone package as well just like geo.

@clintjedwards clintjedwards marked this pull request as ready for review April 1, 2026 02:20
Comment thread fsthttp/resvpnproxy.go Outdated
result := &ResVPNProxyResult{}
var err error

result.IsAnonymous, err = r.callDownstreamBool(r.downstream.req.DownstreamResvpnproxyIsAnonymous)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a helper called ignoreNoneError that you can use for this. See example usage here: https://github.com/fastly/compute-sdk-go/blob/main/fsthttp/backend.go#L111

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the Downstream bool helper and used the ignoreNoneError from the main package.

Comment thread internal/abi/fastly/http_guest.go Outdated
b bool
_ prim.Usize // align padding
}
status := fastlyHTTPDownstreamResvpnproxyIsAnonymous(r.h, prim.ToPointer(&result.b))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our hostcall wrappers generally look like this shorter form:

        if err := fastlyBackendIsDynamic(
                nameBuffer.Data, nameBuffer.Len,
                prim.ToPointer(&dynamic),
        ).toError(); err != nil {
                return false, err
        }
        return dynamic != 0, nil

and I think you should be able that form here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always found the ; err !=nil { pattern a bit harder to read than simply separating them out. But I've updated it for consistency.

) FastlyStatus

// ResVPNProxyLookup returns the Proxy and VPN data associated with the IP address.
func ResVPNProxyLookup(ip net.IP) ([]byte, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't seem to be exposed to the user at all. Should it be?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A holdover from me attempting to first create a more generalizable function instead of one that just works off the request. I first figured we could do that and then just use it everywhere else and also offer it to the user, but then I abandoned due to time constraints.

Good catch, I'll remove.

Comment thread internal/abi/fastly/http_guest.go Outdated
result prim.Pointer[bool],
) FastlyStatus

func (r *HTTPRequest) DownstreamResvpnproxyIsAnonymousVpn() (bool, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vpn -> VPN

Comment thread internal/abi/fastly/http_guest.go Outdated
result prim.Pointer[bool],
) FastlyStatus

func (r *HTTPRequest) DownstreamResvpnproxyIsProxyOverVpn() (bool, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vpn -> VPN

Comment thread internal/abi/fastly/http_guest.go Outdated
result prim.Pointer[bool],
) FastlyStatus

func (r *HTTPRequest) DownstreamResvpnproxyIsSmartDnsProxy() (bool, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dns -> DNS

Comment thread internal/abi/fastly/http_guest.go Outdated
result prim.Pointer[bool],
) FastlyStatus

func (r *HTTPRequest) DownstreamResvpnproxyIsVpnDatacenter() (bool, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vpn -> VPN

Comment thread internal/abi/fastly/http_guest.go Outdated
nwrittenOut prim.Pointer[prim.Usize],
) FastlyStatus

func (r *HTTPRequest) DownstreamResvpnproxyVpnServiceName() (string, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vpn -> VPN

//
//go:wasmimport fastly_resvpnproxy lookup
//go:noescape
func fastlyResVpnProxyLookup(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other places resvpnproxy has been camel-cased as Resvpnproxy. We should be consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I grepped through and tried to correct all instances of this. Good call, its important to be consistent about these things.

Comment thread fsthttp/resvpnproxy.go Outdated

// ResVPNProxyResult represents additional IP Proxy and VPN Intelligence data for a request.
type ResVPNProxyResult struct {
IsAnonymous bool // True if the IP address is present in one or more categories of anonymous flags.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields should have JSON struct tags. (This also means the resvpnproxy example can be simplified to not have to cosntruct the JSON by hand.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! Working in Rust too long, I completely forgot about struct tags for this one.

Copy link
Copy Markdown
Member

@dgryski dgryski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread _examples/resvpnproxy/main.go Outdated
// Test the ResVPNProxy data using the request method
vpnData, err := r.ResVPNProxyData()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread internal/abi/fastly/http_guest.go Outdated
) FastlyStatus

func (r *HTTPRequest) DownstreamResVPNProxyIsAnonymous() (bool, error) {
var result bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You lost the padding structs in all the hostcalls.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I wasn't 100% sure why they were necessary since testing seemed to work without them, but I assume I just got lucky with the alignment.

I've returned them and also refactored my functions to look more like the others in terms of whitespace.

Copy link
Copy Markdown
Member

@dgryski dgryski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot I had a few changes needed: the alignment struct and the http constant.

Adding a lookup function for ResVPNProxy. This enables VPN/Proxy
intelligence data for specific IP addresses.
Copy link
Copy Markdown
Member

@dgryski dgryski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@clintjedwards clintjedwards merged commit 9b64cbf into main Apr 2, 2026
9 checks passed
@clintjedwards clintjedwards deleted the cje/resvpnproxy branch April 2, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants